﻿using JU.MODEL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JU.DAL
{
    public class UserService
    {
        /// <summary>
        /// 根据登录名获得用户
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <returns>用户</returns>
        public static User GetUserByLoginName(string loginName)
        {
            User user = null;
            SqlHelper sqlHelper = new SqlHelper();
            string sql = "Procedure_GetUserByLoginName";
            SqlParameter par = new SqlParameter("@loginName", System.Data.SqlDbType.VarChar,50)
            {
                Value = loginName
            };
            using (SqlDataReader reader = sqlHelper.ExecuteReaderSP(sql, par))
            {
                if (reader.HasRows)
                {
                    if (reader.Read())
                    {
                        user = new User();
                        user.UserId = reader.GetInt32(0);
                        user.LoginId = reader.GetInt32(1);
                        user.UserName = reader.GetString(2);
                        user.Email = reader.GetString(3);
                        user.Phone = reader.GetString(4);
                        user.Birthday = reader.GetDateTime(5);
                        user.PrivinceId = reader.GetInt32(6);
                        user.CityId = reader.GetInt32(7);
                        user.ImagePath = reader.GetString(8);
                    }
                }
            }
            return user;
        }
    }
}
